<?php
namespace Mobile\Model;
use Common\Model\Movie;
use Think\Model;

class ScreeningModel extends Model
{
    public function getAll($id, $time)
    {
        $list = $this->field('
                      u.id uid,
                      u.name uname,
                      u.address uad,
                      m.id  mid,
                      m.name mname,
                      s.id sid,
                      s.showtime stime
                ')
            ->table('pre_user u,pre_movie m,pre_screening s')
            ->where("u.id=s.user_id and m.id=s.movie_id and m.id=$id")
            ->order(array('s.showtime' => 'asc'))
            ->select();
        foreach ($list as $key => $value) {
            $date = date('md', $value['stime']);
            if ($date === $time) {
                $arr[] = $list[$key];
                continue;
            }
        }
        return $arr;
    }

    public function setAll($uid,$mid,$time){
        $list=$this->field('
                      u.id uid,
                      u.name uname,
                      u.address uad,
                      m.id  mid,
                      m.name mname,
                      m.long mg,
                      m.language ml,
                      s.id sid,
                      s.price spr,
                      s.showtime stime,
                      r.id rid,
                      r.name rname
                ')
            ->table('pre_user u,pre_movie m,pre_screening s,pre_room r')
            ->where("u.id=s.user_id and m.id=s.movie_id and m.id=$mid and u.id=$uid and r.id=s.room_id ")
            ->select();
        foreach($list as $key => &$value){
            $date = date('md',$value['stime']);
            $value['mg']=$value['mg']*60;
            $value['ml']=Movie::langAlias($value['ml']);
            if($date===$time){
                $arr[]=$list[$key];
                continue;
            }
        }
        return $arr;
    }


}